package com.example.hutool;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.math.MathUtil;
import cn.hutool.json.JSONUtil;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author 江黎
 * @since 2022-11-08
 */
public class 类型转换工具类 {

    public static void main(String[] args) {
        // 字符串转换为日期
        String time = "2022-11-08 21:00:00";
        Date date = Convert.toDate(time);
        System.out.println(date);

        // long类型转换为日期
        long millis = System.currentTimeMillis();
        date = Convert.toDate(millis);
        System.out.println(date);

        // 集合类型转换
        List<Integer> integers = Arrays.asList(111, 222, 333);
        List<Object> objects = Convert.toList(Object.class, integers);
        System.out.println(objects);

        // 字符串转字符串数组
        String str = "admin,guest";
        String[] strArr = Convert.toStrArray(str);
        System.out.println(JSONUtil.toJsonStr(strArr));

        // 数字转换为大写汉字金额
        double yuan = MathUtil.centToYuan(16050);
        System.out.println(yuan);
        long cent = MathUtil.yuanToCent(yuan);
        System.out.println(cent);
        String chinese = Convert.digitToChinese(yuan);
        System.out.println(chinese);

    }
}
